function maxChunksToSorted(arr: number[]): number {
    let stack: number[] = []
    for (let i = 0; i < arr.length; i++) {
        // 当前 arr[i] 大于 stack 最后一个值。则push 到stack中
        if (stack.length === 0 || stack[stack.length - 1] <= arr[i]) {
            stack.push(arr[i])
        } else {
            const temp = Number(stack.pop());
            while (stack[stack.length - 1] > arr[i]) {
                console.log(stack[stack.length - 1], '------------', arr[i], i)
                stack.pop();
            }
            stack.push(temp);
        }
    }
    console.log(stack);
    return stack.length
}

// console.log(maxChunksToSorted([2,1,3,4,4]));
// console.log(maxChunksToSorted([5,4,3,2,1]));
// console.log(maxChunksToSorted([1, 1, 0, 0, 1]));
